package com.hfjyz.registration.task;

public class TaskManager {
	private Task task;
	private int retryCount = 20;
	private long retryInterval = 1000 * 60 * 3;

	public TaskManager(Task task) {
		this.task = task;
	}

	public TaskManager(Task task, int retryCount, int retryInterval) {
		this.task = task;
		this.retryCount = retryCount;
		this.retryInterval = retryInterval;
	}

	public void start() throws Exception {
		new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					int success = 1;
					int executedCount = 0;
					do {
						if (executedCount > 0) {
							Thread.sleep(retryInterval);
						}
						executedCount++;
						success = task.execute();
					} while (executedCount < retryCount && success == 2);
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}).start();
	}
}
